import { defineStore } from 'pinia'

export const carStore = defineStore('carStore',{
	state: ()=>{
		return {
			count:0,
			//购物车数据
			carList:[]
		}
	},
	actions:{
		increment(){
			this.count++
		},
		//加入购物车
		addCar(goods){
			//判断提交的商品是否已经存在于购物车
			const flag = this.carList.findIndex(item => goods.goodsId == item.goodsId)
			if(flag > -1){//存在,删除原来的数据
				this.carList.splice(flag,1)
			}
			this.carList.push(goods)
		}
	},
})